#pragma once
#include "XFtpTask.h"
#include <map>
#include <string>

class XFtpSession:public XFtpTask
{
public:
	XFtpSession(evutil_socket_t fd);
	virtual ~XFtpSession();
    virtual bool init();
    virtual void read(bufferevent *bev);
    virtual void handleEvent(bufferevent *bev, short what);
    virtual void responseFtpCmd(const std::string &msg);
    virtual void connectDataChannel(XFtpTask *task);
    virtual void sendData(const std::string &data);
    virtual void sendData(const char *data, size_t size);
    virtual void disconnectDataChannel();
    void registerCommand(const std::string &cmd, XFtpTask *handler);
    void setFtpCommandChannel(bufferevent *ev);
    bufferevent *getFtpCommandChannel() const;
    std::string getCurDir() const;
    void setCurDir(const std::string dir);
    std::string getRootDir() const;
    void setDataChannelInfo(const std::string& ip, const unsigned short port);
protected:
    void dispach();
private:
    std::map<std::string, XFtpTask *> mCommands;
    std::string mCommandLine;
    evutil_socket_t mSock = -1;
    std::string mCurDir;
    std::string mRootDir;
    bufferevent *mCommandChannel = nullptr;
    bufferevent *mDataChannel = nullptr;
    std::string mDataChannelIP;
    unsigned short mDataChannelPort;
};

